#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2024/2/4 15:48
# @Author  : 王凯
# @File    : main.py
# @Project : meituan
import json
import subprocess
from functools import partial
from pathlib import Path

subprocess.Popen = partial(subprocess.Popen, encoding="utf-8")
import execjs

with open(
        rf"{Path(__file__).parent.as_posix()}/slider_encrypt.243a0f0144.js",
        "r",
        encoding="utf-8",
) as f:
    js_code = f.read()


def mt_get_slider_params(
        config, host='https://epassport.meituan.com',
        referer="https://ecom.meituan.com/bizaccount/login.html?loginByPhoneNumber=true&isProduction=true&epassportParams=%3Fbg_source%3D1%26service%3Dcom.sankuai.meishi.fe.ecom%26part_type%3D0%26feconfig%3Dbssoify%26biz_line%3D1%26continue%3Dhttps%253A%252F%252Fecom.meituan.com%252Fbizaccount%252Fbiz-choice.html%253Fredirect_uri%253Dhttps%25253A%25252F%25252Fecom.meituan.com%25252Fmeishi%25252F%2526_t%253D1678415645931%2526target%253Dhttps%25253A%25252F%25252Fecom.meituan.com%25252Fmeishi%25252F%26leftBottomLink%3D%26signUpTarget%3Dself"):
    config = json.dumps(config)
    return execjs.compile(js_code).call("get_slider_params", config, host, referer)
